package com.yang.frost.blueberry.service.impl;

import com.yang.frost.blueberry.mapper.CmsArticleCategoryMapper;
import com.yang.frost.blueberry.mapper.CmsArticleMapper;
import com.yang.frost.blueberry.params.CmsArticlePageOrderParam;
import com.yang.frost.blueberry.service.CmsArticleService;
import com.yang.frost.blueberry.util.ApiResult;
import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 10296
 * @date 2021/3/10
 * @Description:
 */
@Service
public class CmsArticleServiceImpl implements CmsArticleService {

    private Logger logger = LoggerFactory.getLogger(CmsArticleService.class);
    @Autowired
    private CmsArticleMapper cmsArticleMapper;
    @Autowired
    private CmsArticleCategoryMapper cmsArticleCategoryMapper;

    @Override
    public ApiResult qryArticleList(CmsArticlePageOrderParam articleParam) {

        Map<String, Object> resultMap = new HashMap<>();

        List<Map<String, Object>> maps = cmsArticleMapper.qryArticleList(articleParam);
        resultMap.put("rows", maps);
        int pageIndex = Math.toIntExact(articleParam.getPageIndex());
        int pageSize = Math.toIntExact(articleParam.getPageSize());
        resultMap.put("page", pageIndex);
        int counts = cmsArticleMapper.qryArticleCounts(articleParam);
        resultMap.put("records", counts);
//        int total = counts / pageSize;
        resultMap.put("total", counts);
        logger.info(">>>>>>>查询文章列表>>>>>>>>>>" + resultMap);
        return ApiResult.ok(resultMap);

    }

    @Override
    public ApiResult insertArticle(Map<String, Object> paramsMap) {
        int i = cmsArticleMapper.insertArticle(paramsMap);
        int insert = cmsArticleCategoryMapper.insert(paramsMap);
        return ApiResult.ok(i);
    }

    @Override
    public ApiResult updateArticle(Map<String, Object> paramsMap) {
        return null;
    }

    @Override
    public ApiResult deleteArticle(Map<String, Object> paramsMap) {
        int i = cmsArticleMapper.delArticle(paramsMap);


        return ApiResult.ok(i);
    }

    @Override
    public ApiResult batchDeleteArticle(Map<String, Object> paramsMap) {
        return null;
    }
}
